package Calculator;

import java.util.Scanner;

/**
 * @author SWJ
 * @create 2021-06-26 11:04
 * //2.实现基本图形计算(面积 周长)：圆形π=3.14，正方形，长方形
 */
public class GraphicCalculation {
    public void GraphicCalculation() {
        System.out.println("本方法用来计算图形的实现基本" +
                "图形计算(面积 周长)：圆形π=3.14，正方形，长方形，三角形" +
                "(1面积 2周长)请输入关键字：");
        do {
            int g1 = new Scanner(System.in).nextInt();
            //用来判断进行关键字选择1/2的面积和周长
            if (g1 == 1 || g1 == 2) {
                System.out.println("1圆形π=3.14，2正方形，3长方形 4三角形");
                int g2 = new Scanner(System.in).nextInt();
                if (g2 > 0 && g2 <= 4) {
                    if (g1 == 1) {
                        //计算面积
                        System.out.println("开始为您计算面积：");
                        switch (g2) {
                            case 1:
                                circular ci = new circular();
                                ci.circularPerimeter();
                                break;
                            case 2:
                                square sq = new square();
                                sq.sqaurarea();
                                break;
                            case 3:
                                triangle ti = new triangle();
                                ti.trianglearea();
                        }

                    } else {
                        //计算周长
                        System.out.println("开始为您计算图形周长：");
                        switch (g2) {
                            case 1:
                                circular ci2 = new circular();
                                ci2.circulararea();
                                break;
                            case 2:
                                square s2=new square();
                                s2.sqaurmeter();
                                break;
                        }
                    }
                } else {
                    System.out.println("输入错误请重新输入！");
                    continue;
                }

            } else {
                System.out.println("输入错误请重新输入！");
                continue;
            }

        } while (true);

    }
}

class Test {
    double input1 = 0.0;

    public double test1() {
//测试数据的输入数值
        do {
            double input1 = new Scanner(System.in).nextDouble();
            if (input1 <= 0) {
                System.out.println("输入错误请重新输入！不能小于等于0");
                continue;
            } else {
                System.out.println("你输入的是" + input1);
                return input1;
            }
        } while (true);

    }

}

class circular extends Test {
    //计算圆形的面积周长

    public void circularPerimeter() {
//计算圆形周长
        do {
            System.out.println("请输入圆形的1半径或者2直径");
            int input2 = new Scanner(System.in).nextInt();
            if (input2 == 1 && input2 == 2) {
                switch (input2) {
                    case 1:
                        Test t1 = new Test();
                        t1.test1();
                        double sum = input1 * 3.141;
                        System.out.println(sum);
                }
            } else {
                System.out.println("输入错误请重新输入！必须是半径或者直径");
                continue;

            }
        } while (true);

    }

    public void circulararea() {
        do {
            System.out.println("请输入圆形的1半径或者2直径");
            int input2 = new Scanner(System.in).nextInt();
            if (input2 == 1 && input2 == 2) {
                switch (input2) {
                    case 1:
                        Test t1 = new Test();
                        t1.test1();
                        double sum = input1 * 3.141 * input1;
                        System.out.println(sum);
                }
            } else {
                System.out.println("输入错误请重新输入！必须是半径或者直径");
                continue;

            }
        } while (true);


    }
}

class square extends Test {
    //计算正方形 长方形的面积周长


    public void sqaurmeter() {
        System.out.println("请输入长方形的长度");
        Test t1 = new Test();
        t1.test1();
        double sum = input1;
        System.out.println("请输入长方形的宽度");
//        Test t2t1 = new Test();
        t1.test1();
        double sum2t1 = input1;
        double sum3t1 = (sum + sum2t1) * 2;
        System.out.println("周长是" + sum3t1);
    }

    public void sqaurarea() {
        System.out.println("请输入长方形的长度");
        Test t1 = new Test();
        t1.test1();
        double sumt1 = input1;
        System.out.println("请输入长方形的宽度");
//        Test t2 = new Test();
        t1.test1();
        double sumt2 = input1;
        double sumt3 = sumt1 * sumt2;
        System.out.println("面积是" + sumt3);

    }
}

class triangle extends Test {
    //计算三角形面积
    public void trianglearea() {
        System.out.println("请输入三角形的底边长");
        Test t1 = new Test();
        t1.test1();
        double sum = input1;
        System.out.println("请输入三角形高");
        Test t2 = new Test();
        t1.test1();
        double sum2 = input1;
        double sum3 = (sum * sum2) / 2;
        System.out.println("面积是" + sum3);
    }
}
